package com.huichaoliu.adapters;

import java.util.List;

import com.huichaoliu.app.R;
import com.huichaoliu.data.Config;
import com.huichaoliu.data.UtilInfo;
import com.rederxu.AsyncTask.ImageTask;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class FragmentShoppingAdapter extends BaseAdapter {
	List<UtilInfo> list;
	Context context;
	LayoutInflater inflater;

	public FragmentShoppingAdapter(List<UtilInfo> list, Context context) {
		this.list = list;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		Holder mHolder;
		if (arg1 == null || arg1.getTag() == null) {
			mHolder = new Holder();
			arg1 = inflater.inflate(R.layout.shopping_fragment_item, arg2,
					false);
			mHolder.check = (ImageView) arg1
					.findViewById(R.id.shopping_item_check);
			mHolder.clothes = (ImageView) arg1
					.findViewById(R.id.shopping_item_clothes);
		} else {
			mHolder = (Holder) arg1.getTag();
		}
		Log.i("Hello", "path=" + list.get(arg0).getPicPath());
		ImageTask it = new ImageTask(mHolder.clothes, Config.getFolderImages(),
				null);
		it.execute(list.get(arg0).getPicPath());

		if (list.get(arg0).isCheck()) {
			mHolder.check.setVisibility(View.VISIBLE);
		} else {
			mHolder.check.setVisibility(View.GONE);
		}

		return arg1;
	}

	public class Holder {
		ImageView check;
		ImageView clothes;

	}

}
